package no.rmz.chez.game.moveSelection;

import java.util.Collection;



public class ExponentialBackoffSelector<T> extends Selector<T> {

    final private static Double selectionPossibiliy = 0.3;
    
    /**
     * Iterate through the elements of the collection, at each iteration, there is
     * a possibility, given by the selectionPossibility parameter, that the
     * element being iterated over will be chosen. When the last element in the
     * collection has been reached, a new interation over the entire collection
     * starts.
     * @param possCollection
     * @return An element.
     */
    @Override
    public T  selectFrom(Collection<T> possCollection) {
        while (true) {
            for (T e: possCollection) {
                if (getRandom().nextDouble() < selectionPossibiliy) {
                    return e;
                }
            }
        }
    }
}
